<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\BookChapter as BookChapterModel;

/**
 * BookCapter 章节控制器
 * Class BookChapter
 * @package app\home\controller
 */
class BookChapter extends Base
{
    /**
     * [getIndex  获取本书所有章节]
     * @param
     * @return json
     * @author [C。]
     */
    public function getIndex()
    {
        $param = input('param.');
        $this->getPageAndSize($param);
        $model = new BookChapterModel();
        $map = [];
        try{
            $map['status'] = 1;
            $map['bookid'] = $param['id'];
            $lists = $model->getlists($map);
//            $count = $model->getCount($map);//满足条件的总数
//            $allpage = intval(ceil($count / $this->size));//总页数
//            $lists = $model->getlist($map, $this->from, $this->size);
        }catch (\Exception $e) {
            systembug($e->getMessage(),2,'home/BookChapter/getIndex');
            return admin_json(-1,'查看章节失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',$lists);
    }
    /**
     * [getIndex  获取本书所有章节]
     * @param
     * @return json
     * @author [C。]
     */
    public function getChapter()
    {
        $param = input('param.');
        $model = new BookChapterModel();
        try{
            $chapter = $model->findData($param['id'],'id');
        }catch (\Exception $e) {
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1,'查看章节失败'.$e->getMessage());
        }
        return admin_json(1,'查看章节成功',$chapter);
    }
}